package writtenTraining.day38;

import java.io.*;
import java.util.*;

/**
 * day38:(1)动态规划：天使果冻
 */
public class Main {
    public static void main(String[] args) {
//         动态规划
        // 输入数据
        Scanner in  = new Scanner(System.in);
        int n = in.nextInt();
        int[] dp = new int[n+1];
        
        int INF = 0x3f3f3f3f;
        int max = -INF, prev = -INF;
        for(int i = 1; i <= n; i++){
            int num = in.nextInt();
            if(num > max) {
//                 更新前面的次小值
                if(max > prev) {
                    prev = max;
                }
                max = num;
                
            } else if(num > prev) {
                prev = num;
            } 
            
            dp[i] = prev;
       
        }
        
        
        int q = in.nextInt();
        while(q-- > 0) {
            int index = in.nextInt();
             System.out.println(dp[index]);
        }        
    }
}



 class Main2 {
    public static void main(String[] args) {
//         输入数据
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int[][] nums = new int[n][n];

        for(int i = 0; i < n; i++) {
            for(int j =0; j < n; j++) {
                nums[i][j] = in.nextInt();
            }
        }

        change(nums,n,1);

        for(int i = 0; i < n; i++) {
            for(int j =0; j < n; j++) {
                System.out.print(nums[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static void change(int[][] nums, int n, int index) {
        int[][] ret = new int[n][n];
        if(index == 1) {
            for(int i = 0; i < n; i++) {
                for(int j =0; j < n; j++) {
                    ret[i][j] = nums[n - i - 1][n - j - 1];
                }
            }
        } else {
            for(int i = 0; i < n ; i++) {
                for(int j = 0 ; j < n; j++) {
                    ret[i][j] = nums[n - i - 1][j];
                }
            }
        }

        for(int i = 0; i < n ; i++) {
            for(int j = 0 ; j < n; j++) {
                nums[i][j] = ret[i][j];
            }
        }
    }
}







/**
 * day38:(2)数学 + 模拟:dd爱旋转
 */

 class Main3 {
    public static void main(String[] args)throws IOException {
//         数学 + 模拟
//         180 = 行 + 列
        // 输入数据
        Read in = new Read();
        PrintWriter out = new PrintWriter(new
                BufferedWriter(new OutputStreamWriter(System.out)));
//         Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int[][] nums = new int[n][n];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                nums[i][j] = in.nextInt();
            }
        }

        int q = in.nextInt();
        int row = 0, col = 0;
        while(q-- > 0) {
            int num = in.nextInt();
            if(num == 1) {
                col++;
            }
            row++;
        }

        row %= 2; col %= 2;
        while(row-- > 0) {
            changeRow(nums);
        }
        while(col -- > 0) {
            changeCol(nums);
        }


        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n - 1; j++) {
                out.print(nums[i][j] + " ");
            }
            out.println(nums[i][n - 1]);
        }

        out.close();
    }

    public static void changeRow(int[][] nums) {
        int n = nums.length;
        for(int i = 0; i < n / 2; i++) {
            for(int j = 0; j < n; j++) {
                swap(nums,i,j,n - i - 1, j);
            }
        }
    }

    public static void changeCol(int[][] nums) {
        int n = nums.length;
        for(int i = 0; i < n; i++) {
            for(int j =0; j < n / 2; j++) {
                swap(nums,i,j,i,n - j - 1);
            }
        }
    }

    public static void swap(int[][]nums,
                            int i , int j
            ,int di , int dj) {
        int tmp = nums[i][j];
        nums[i][j] = nums[di][dj];
        nums[di][dj] = tmp;
    }


}





class Read // 自定义快速读入
{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException
    {
        while(!st.hasMoreTokens())
        {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException
    {
        return bf.readLine();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
}


/**
 * day38:(3)01背包+同余定理:  DP40 小红取数
 */


class Main4 {
    public static void main(String[] args) {
        // 01 背包 + 同余定理
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt();
        long[] nums = new long[n + 1];

        // 预处理
        for(int i = 1; i <= n; i++) {
            nums[i] = in.nextLong();
        }

        // 创建dp
        long INF = 0x3f3f3f3f3f3f3f3fL;
        long[][] dp = new long[n + 1][k];
        // 初始化
        for(int i = 0 ; i <= n; i++) {
            for(int j = 0; j < k; j++) {
                dp[i][j] = -INF;
            }
        }
        // 0 % 0 = 0
        dp[0][0] = 0;

        for(int i = 1 ; i <= n; i++) {
            for(int j = 0; j < k; j++) {
                // 先继承前面的
                // 寻找前面的余数
                dp[i][j] = Math.max(dp[i-1][j]
                        , dp[i-1][(int)((((long)j - nums[i])
                                % (long)k + (long)k) % (long)k)] + nums[i]);
            }
        }

        //
        System.out.println(dp[n][0] > 0 ? dp[n][0] : -1);
    }
}